package org.example.tialsproject.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.tialsproject.mapper.DeptMapper;
import org.example.tialsproject.pojo.Dept;
import org.example.tialsproject.pojo.Emp;
import org.example.tialsproject.pojo.PageBean;
import org.example.tialsproject.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImp implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /*获取所有部门列表的方法(支持分页)*/
    @Override
    public PageBean getAllDepts(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Dept> p = (Page<Dept>) deptMapper.getAllDepts();
        return new PageBean(p.getTotal(), p.getResult());
    }

    /*根据ID删除部门方法*/
    @Override
    public void deleteDept(int id) {
        deptMapper.deleteDept(id);
    }

    /*添加部门方法*/
    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.addDept(dept);
    }

    /*根据ID查询部门的方法*/
    @Override
    public Dept getDeptDetail(int id) {
        return deptMapper.getDeptDetail(id);
    }

    /*根据ID编辑部门的方法*/
    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateDept(dept);
    }
}
